cmake_minimum_required(VERSION 3.5)
project(custom_tensor_pkg)

option(CUDA_USE_STATIC_CUDA_RUNTIME OFF)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_BUILD_TYPE Release)#Debug#Release
#set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/workspace)
#set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/workspace)

# 如果你的opencv找不到，可以自己指定目录
#set(OpenCV_DIR   "/datav/lean/opencv-4.2.0/lib/cmake/opencv4/")
find_package(CUDA REQUIRED)
find_package(OpenCV)

include_directories(
    ${PROJECT_SOURCE_DIR}/core
    ${OpenCV_INCLUDE_DIRS}
    ${CUDA_INCLUDE_DIRS}
)

message(${CUDA_INCLUDE_DIRS})
message(${CUDA_LIBRARIES})

# 如果你是不同显卡，请设置为显卡对应的号码参考这里：https://developer.nvidia.com/zh-cn/cuda-gpus#compute
set(CUDA_GEN_CODE "-gencode=arch=compute_61,code=sm_61")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -O0 -Wfatal-errors -pthread -w -g")
set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -std=c++11 -O0 -Xcompiler -fPIC -g -w ${CUDA_GEN_CODE}")

file(GLOB_RECURSE cpp_srcs ${PROJECT_SOURCE_DIR}/core/*.cpp)
set(ITensorCppSo "ITensorCpp")
#add_library(${ITensorCppSo} SHARED ${cpp_srcs})
add_library(${ITensorCppSo} ${cpp_srcs})
target_link_libraries(${ITensorCppSo} ${CUDA_LIBRARIES} cuda)
target_link_libraries(${ITensorCppSo} pthread)

include_directories(${PROJECT_SOURCE_DIR}/test)
file(GLOB_RECURSE cu_files1 ${PROJECT_SOURCE_DIR}/test/*.cu)
set(kernelCuSo "kernelCu")
cuda_add_library(${kernelCuSo} ${cu_files1})
target_link_libraries(${kernelCuSo} ${CUDA_LIBRARIES} cuda ${CUDA_cublas_LIBRARIES})
target_link_libraries(${kernelCuSo} pthread)

file(GLOB_RECURSE cpp_files1 ${PROJECT_SOURCE_DIR}/test/*.cpp)
set(testProj "test1")
add_executable(${testProj} ${cpp_files1})
target_link_libraries(${testProj} ${CUDA_LIBRARIES} cuda ${OpenCV_LIBS})
target_link_libraries(${testProj} ${ITensorCppSo} ${kernelCuSo})


